﻿#pragma once
/**
@author 何炜
@date 2011/4/27
@brief .
@details
*/

namespace GLL
{
	template<class T>
	class Singleton
	{
	protected:
		static T* _this;
	public:
		Singleton(){if(!_this)_this = static_cast<T*>( this );}
		virtual ~Singleton(){}
		static T& Ref(){return *_this;}
		static T* Ptr(){return _this;}
	};

	template<class T> T* Singleton<T>::_this = 0;

	///使子类继承singleton类后，Ref() 返回本类，而不是父类
#define GLL_SINGLETON(derived) 	\
	static derived& Ref(){return (derived&)*_this;}\
	static derived* Ptr(){return (derived*)_this;}

};//GLL
